package controller;
import java.io.File;
import model.DataLoader;
import model.Table;
import view.Displayer;

/**
 * Controller calls model to parse a file, and calls View to display
 * @author Rex Ying
 */

public class Controller {
    private Displayer myDisplay;
    private DataLoader myDataLoader;

    /**
     * construct a controller that contains Display and DataLoader
     */
    public Controller() {
        String[] initString = new String[] {"nothing to be displayed:("};
        myDisplay = new Displayer("College Ranking", "English", this, initString);
        myDataLoader = new DataLoader(this);
    }

    /**
     * Call getSubTable in DataLoader
     * @param categories Data in these specified categories are to be fetched
     * @return the sub-table
     */
    public Table getSubTable(String[] categories) {
        return myDataLoader.getSubTable(categories);
    }

    /**
     * show error in the GUI
     * @param errorMessage the error message to be displayed
     */
    public void showError(String errorMessage) {
        myDisplay.showError(errorMessage);
    }

    /**
     * Identifies file type and calls the appropriate parse method
     *
     * @param file chosen by user
     */
    public boolean parse (File file) {
        return myDataLoader.parse(file);
    }

    /**
     * get the categories available from DataLoader
     * @return a series of categories
     */
    public String[] getCategories() {
        return myDataLoader.getCategories();
    }

    /**
     * Main Entry
     * @param args no arguments are currently used
     */
    public static void main(String[] args) {
        new Controller();
    }
}
